//
//  CommonFunc.swift
//  BaseModule_Example
//
//  Created by seven on 2020/7/1.
//  Copyright © 2020 CocoaPods. All rights reserved.
//

import UIKit

internal func SLLog(_ msg: Any,
                    file: NSString = #file,
                    line: Int = #line,
                    fn: String = #function) {
    #if DEBUG
    let arr = file.lastPathComponent.components(separatedBy: ".")
    let prefix = "😂-->\(arr.first!) \(fn) 第 \(line) 行 <---😂\n"
    print(prefix, msg); print(" ")
    #endif
}

internal func RGBColor(_ color: Int) -> UIColor {
    UIColor(red: CGFloat((color & 0xFF0000) >> 16) / 255.0,
            green: CGFloat((color & 0x00FF00) >> 8) / 255.0,
            blue: CGFloat(color & 0x0000FF) / 255.0,
            alpha: 1.0)
}

internal func fit(_ num: CGFloat) -> CGFloat {
    let s = UIView.scale
    return s == 1.0 ? num : num * s
}

internal let kScreenW = UIScreen.main.bounds.width
internal let kScreenH = UIScreen.main.bounds.height
internal let kHalfScreenW = kScreenW * 0.5
internal let kHalfScreenH = kScreenH * 0.5

/// 是否为iphoneX系列
let isIphoneX: Bool = {
    guard #available(iOS 11.0, *) else {
        return false
    }
    return UIApplication.shared.windows[0].safeAreaInsets.bottom != 0
}()

/// 安全区域顶部高度(导航栏高度)
let kSafeTopH: CGFloat = {
    guard #available(iOS 11.0, *) else {
        return 64
    }
    var top = UIApplication.shared.windows[0].safeAreaInsets.top
    if top == 0 {
        top = 20
    }
    return top + 44
}()

/// 底部安全高度
let kSafeBottomH: CGFloat = {
    guard #available(iOS 11.0, *) else {
        return 0
    }
    return UIApplication.shared.windows[0].safeAreaInsets.bottom
}()

/// 状态栏高度
let kStatusBarH: CGFloat = {
    guard #available(iOS 11.0, *) else {
        return 20.0
    }
    var top = UIApplication.shared.windows[0].safeAreaInsets.top
    if top == 0 {
        top = 20
    }
    return top
}()
